"use strict";
module.exports = {
  /**
   * 修改代办状态
   * @url client/todo/kh/setTodoStatus 前端调用的url参数地址
   * data 请求参数
   * @param {String} params1  参数1
   */
  main: async (event) => {
    let { data = {}, userInfo, util, filterResponse, originalParam } = event;
    let { customUtil, uniID, config, pubFun, vk, db, _, $ } = util;
    let { uid } = data;
    let res = { code: 0, msg: "" };
    // 业务逻辑开始-----------------------------------------------------------

    if (!data._id) return { code: -1, msg: "缺少待办ID" };
    if (data.status !== 0 && data.status !== 1)
      return { code: -1, msg: "状态值不合法" };

    let updateRes = await vk.baseDao.update({
      dbName: "dfb-todo",
      whereJson: {
        _id: data._id,
        user_id: uid,
      },
      dataJson: {
        status: data.status,
        complete_time: data.status
          ? vk.pubfn.timeFormat(Date.now(), "yyyy-MM-dd hh:mm")
          : "",
      },
    });

    if (updateRes.updated === 0) return { code: -1, msg: "更新失败" };
    res.msg = "状态更新成功";
    // 业务逻辑结束-----------------------------------------------------------
    return res;
  },
};
